package com.fmatos.service.album.domain;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import com.fmatos.controller.directory.AlbumDirectory;
import com.fmatos.service.album.downloader.info.AlbumInfo;

public class Album {
	
	private static final DateFormat DATE_FORMAT = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
	
	private String name;
	private String niceName;
	private String link;
	private String alternativeLink;
	private List<Photo> photos;

	private String date;

	public Album() {
		buildDate();
	}

	public Album(String albumName) {
		this.name = albumName;
		AlbumInfo albumInfo =  AlbumDirectory.findAlbumByName(albumName);
		if ( albumInfo != null ) {
			niceName = albumInfo.getNiceName();
		} else {
			niceName = null;
		}
		buildDate();
	}
	
	
	
	public Album(String name, String niceName, String link,
			String alternativeLink, List<Photo> photos) {
		super();
		this.name = name;
		this.niceName = niceName;
		this.link = link;
		this.alternativeLink = alternativeLink;
		this.photos = photos;
		buildDate();
	}

	// TODO use joda time
	private void buildDate() {
		Date today = Calendar.getInstance().getTime();      
		date = DATE_FORMAT.format(today);
	}

	public String getDate() {
		return date;
	}

	public String getNiceName() {
		return niceName;
	}

	public List<Photo> getPhotos() {
		return photos;
	}

	public void setPhotos(List<Photo> photos) {
		this.photos = photos;
	}

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("Album [getClass()=");
		builder.append(getClass());
		builder.append(", hashCode()=");
		builder.append(hashCode());
		builder.append(", toString()=");
		builder.append(super.toString());
		builder.append("]");
		return builder.toString();
	}

	public String getLink() {
		return link;
	}

	public void setLink(String link) {
		this.link = link;
	}

	public String getName() {
		return name;
	}

	public String getAlternativeLink() {
		return alternativeLink;
	}

	public void setAlternativeLink(String alternativeLink) {
		this.alternativeLink = alternativeLink;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setNiceName(String niceName) {
		this.niceName = niceName;
	}
	
}
